package com.cssnj.portal.web.user;

import com.cssnj.portal.domain.common.UserInfo;
import com.cssnj.portal.service.user.EvaluateService;
import io.predictech.framework.domain.common.JsonRequest;
import io.predictech.framework.domain.common.JsonResponse;
import io.predictech.framework.domain.exception.BaseException;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

@Controller
@RequestMapping({"/user/evaluate"})
public class EvaluateController {
    @Autowired
    private EvaluateService evaluateService;

    @RequestMapping({"/init.do"})
    public ModelAndView init(HttpServletRequest request) throws BaseException, SQLException {
        //页面初始化
        String gnid = request.getParameter("gnid");
        JsonRequest jsonRequest = new JsonRequest();
        jsonRequest.setServiceName("evaluateService");
        jsonRequest.setHandleCode("init");
        jsonRequest.getReqData().put("gnid", gnid);
        JsonResponse jsonResponse = evaluateService.execute(jsonRequest);
        String gnmc = (String) jsonResponse.getRepData().get("gnmc");
        ModelAndView modelAndView = new ModelAndView("user/evaluate");
        modelAndView.getModelMap().put("gnid", gnid);
        modelAndView.getModelMap().put("gnmc", gnmc);
        return modelAndView;
    }


    @RequestMapping(value = {"/queryPjLb.do"})
    @ResponseBody
    public String queryGnDjLb(HttpServletRequest request) throws BaseException, SQLException {
        //查询评价列表
        JsonRequest jsonRequest = new JsonRequest();
        UserInfo userInfo = (UserInfo) SecurityUtils.getSubject().getPrincipal();
        jsonRequest.setServiceName("evaluateService");
        jsonRequest.setHandleCode("queryPjLb");
        jsonRequest.getReqData().put("page", request.getParameter("page"));
        jsonRequest.getReqData().put("rows", request.getParameter("rows"));
        jsonRequest.getReqData().put("gnid", request.getParameter("gnid"));
        JsonResponse jsonResponse = evaluateService.execute(jsonRequest);
        String str = (String) jsonResponse.getRepData().get("str");
        return str;
    }


    @RequestMapping(value = {"/savePj.do"})
    @ResponseBody
    public JsonResponse savePj(HttpServletRequest request) throws BaseException, SQLException {
        //保存评价
        JsonRequest jsonRequest = new JsonRequest();
        UserInfo userInfo = (UserInfo) SecurityUtils.getSubject().getPrincipal();
        jsonRequest.setServiceName("evaluateService");
        jsonRequest.setHandleCode("savePj");
        jsonRequest.getReqData().put("gnid", request.getParameter("gnid"));
        jsonRequest.getReqData().put("wdpf", request.getParameter("wdpf"));
        jsonRequest.getReqData().put("wdpj", request.getParameter("wdpj"));
        jsonRequest.getReqData().put("swrydm", userInfo.getSwryDm());
        jsonRequest.getReqData().put("swryxm", userInfo.getSwryXm());
        jsonRequest.getReqData().put("swrysfdm", userInfo.getSwrySfDm());
        jsonRequest.getReqData().put("swrysfmc", userInfo.getSwrySfMc());
        jsonRequest.getReqData().put("swjgdm", userInfo.getSfswJgDm());
        jsonRequest.getReqData().put("swjgmc", userInfo.getSfswJgMc());
        JsonResponse jsonResponse = evaluateService.execute(jsonRequest);
        return jsonResponse;
    }

    @RequestMapping(value = {"/queryLsPf.do"})
    @ResponseBody
    public JsonResponse queryLsPf(HttpServletRequest request) throws BaseException, SQLException {
        //记录本人功能菜单点击记录
        JsonRequest jsonRequest = new JsonRequest();
        UserInfo userInfo = (UserInfo) SecurityUtils.getSubject().getPrincipal();
        jsonRequest.setServiceName("userService");
        jsonRequest.setHandleCode("queryLsPf");
        jsonRequest.getReqData().put("gnid", request.getParameter("gnid"));
        JsonResponse jsonResponse = evaluateService.execute(jsonRequest);
        return jsonResponse;
    }
}
